/**
 * Copyright 2007-2008. Chongqing First Information & Network Co., Ltd. All rights reserved.
 * <a>http://www.cqfirst.com.cn</a>
 */
package com.cqcis.uip.base.framework.core.impl;

import java.util.List;

import com.cqcis.uip.base.framework.common.Role;
import com.cqcis.uip.base.framework.common.Task;
import com.cqcis.uip.base.framework.core.RegisteredServiceContext;
import com.cqcis.uip.base.framework.core.Service;
import com.cqcis.uip.base.framework.core.ServiceRole;
import com.cqcis.uip.base.framework.handlers.TableDispatchService;


/**
 * @author huangmy
 * @date 2008-1-11
 */
public class TableDispatchServiceAdaptor implements TableDispatchService {
	private TableDispatchService tableDispatchService;

	public List<Task> get(String interfaceId) throws Exception {
		return this.tableDispatchService.get(interfaceId);
	}

	public boolean processResult(List<Task> results) {
		return this.tableDispatchService.processResult(results);
	}

	public boolean schedule(Task task) throws Exception {
		return this.tableDispatchService.schedule(task);
	}

	public void start(RegisteredServiceContext serviceContext) throws Exception {		
		if (tableDispatchService == null) {
			throw new RuntimeException("the handler's depended service must not be null.");
		}  

		if (tableDispatchService instanceof Service) {
			((Service) tableDispatchService).start(serviceContext);
		}
	}

	public void stop(RegisteredServiceContext serviceContext) throws Exception {
		if (tableDispatchService instanceof Service) {
			((Service)tableDispatchService).stop(serviceContext);
		}		
	}

	@ServiceRole(Role.TABLE)
	public void setTableDispatchService(TableDispatchService tableDispatchService) {
		this.tableDispatchService = tableDispatchService;
	}
}
